package com.zzy.task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import com.zzy.mq.MessageSender;


/**
 * 定时调用 消息
 */
@Component
public class MqTask {

    @Autowired
    private MessageSender messageSender;


    /**
     * 每天0点执行一次[cron顺序:秒-分-小时]
     * */
    //@Scheduled(cron="0 0 0 * * ?")
    public void executeEveryDayAt0h(){
        Date date = new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(date)+"：开始执行任务!");
        System.out.println("执行中");
        Date date2 = new Date();
        System.out.println(sdf.format(date2)+"：执行任务完毕!");
    }


    /**
     * 每隔10秒执行一次
     * */
    public static  int i = 1 ;
    @Scheduled(cron="*/10 * * * * ?")
    public void execute2sOnce(){
        messageSender.send(i +"： message。");
        i++;
    }
}
